﻿package mortal.game.view.collect
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import extend.language.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.platform.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class CollectController extends Controller
    {
        private const minShowLevel:int = 20;
        private const maxShowLevel:int = 40;

        public function CollectController()
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.RoleLevelUpdate, this.checkShowIcon);
            NetDispatcher.addCmdListener(ServerCommand.SystemClientSettingGot, this.checkShowIcon);
            Dispatcher.addEventListener(EventName.LoginGameSuccess, this.checkShowIcon);
            Dispatcher.addEventListener(EventName.CollectGame, this.onCollectGame);
            Dispatcher.addEventListener(EventName.GetGameDownLoadReward, this.onGetGameDownLoadReward);
            return;
        }// end function

        private function checkShowIcon(param1 = null) : void
        {
            if (ParamsConst.instance.downLoadLanderUrl)
            {
                if (ClientSetting.isInited && !ClientSetting.local.getIsDone(IsDoneType.IsGetGameDownLoadReward) && cache.role.entityInfo.level >= 0)
                {
                    LanderIcon.instance.show();
                    LanderIcon.instance.playEffect();
                }
                else
                {
                    if (LanderIcon.hasInstance())
                    {
                        LanderIcon.instance.stopEffect();
                        LanderIcon.instance.hide();
                    }
                    if (LanderWindow.hasInstance())
                    {
                        LanderWindow.instance.hide();
                    }
                }
            }
            else if (ParamsConst.instance.favoritesUrl)
            {
                if (ClientSetting.isInited && !ClientSetting.local.getIsDone(IsDoneType.HasCollectGame) && cache.role.entityInfo.level >= this.minShowLevel)
                {
                    CollectIcon.instance.show();
                    CollectIcon.instance.playEffect();
                }
                else if (CollectIcon.hasInstance())
                {
                    CollectIcon.instance.stopEffect();
                    CollectIcon.instance.hide();
                }
            }
            return;
        }// end function

        private function onCollectGame(event:DataEvent) : void
        {
            GameProxy.role.getCollectReward();
            if (CollectIcon.hasInstance())
            {
                CollectIcon.instance.hide();
                CollectWindow.instance.hide();
            }
            ClientSetting.local.setIsDone(true, IsDoneType.HasCollectGame);
            ClientSetting.save();
            return;
        }// end function

        private function onGetGameDownLoadReward(event:DataEvent) : void
        {
            var _loc_2:* = PlatformGiftConfig.instance.getGiftNoPlan(5);
            if (_loc_2)
            {
                GameProxy.Platform.getPlatformDownloadGift(_loc_2.id, this.onGetGameDownLoadRewardSuccess);
            }
            else
            {
                MsgManager.showRollTipsMsg(Language.getString(90405));
            }
            return;
        }// end function

        public function onGetGameDownLoadRewardSuccess(param1:AMI_IRole_getPlatFormGift) : void
        {
            ClientSetting.local.setIsDone(true, IsDoneType.IsGetGameDownLoadReward);
            ClientSetting.save();
            this.checkShowIcon();
            return;
        }// end function

    }
}
